<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.List"%>
<%@page import="com.cms.model.Category"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>PayChannel</title>
<script src="./js/strFilter.js" type="text/javascript"></script>
<link href="styles/general.css" rel="stylesheet" type="text/css">
<link href="styles/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/utils.js"></script>
<script>
function txcheck(){
	
	return true;
}
</script>
</head>

<body>
 <h1>
        <span class="action-span"><a href="category_show.do">添加类别</a></span> <span
            class="action-span1"><a href="mainframe.jsp">
                首页</a> </span><span id="search_id" class="action-span1">- 类别管理 </span>
        <div style="clear: both">
        </div>
    </h1>
   <!-- start ad menu list -->
    <div class="list-div" id="listDiv">
        <table width="100%" cellspacing="1" cellpadding="2" id="list-table">
            <tbody id="listbody">
                <tr>
                    <th>
                        类别名称
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
                <%
  	List<Category> list= (List<Category>)request.getAttribute("list");
  	int count = 0;
  	count = 0;
  	if(list!=null && list.size()>0)
  	{
  		int num=0;
  		for(Category mo:list)
  		{
  			if("".equals(mo.getParentId())||mo.getParentId().equals("0"))
  			{
  				count++;
	  			num=0;
	  			for(Category mo1:list)
	  			{
	  				
	  				if((mo.getId()+"").equals(""+mo1.getParentId()))
	  				{
	  					num++;
	  				}
	  			}
	  			%>
	  			<tr align="center" class="0" id="0_<%=mo.getId() %>">
	  			 <td align="left" class="first-cell" style="background-color: rgb(255, 255, 255); ">
               <img src="img/menu_minus.gif" id="icon_0_<%=mo.getId() %>" width="9" height="9" border="0" style="margin-left:0em" onclick="rowClicked(this)">

               <span><%=mo.getCategoryName()%></span>
               </td>
               <td width="24%" align="center" style="background-color: rgb(255, 255, 255); ">
               		<s:if test="isUpdate.equals('true')">
	    			<a  title="编辑" href="category_show.do?type=upd&model.id=<%=mo.getId() %>">
						<img height="16" width="16" border="0" src="img/icon_edit.gif" alt="编辑">
					</a> 
	    			<%
	    				if(num==0)
	    				{
	    			%>
					<a href="category_save.do?type=del&model.id=<%=mo.getId() %>" onclick="return window.confirm('警告！！确定要删除吗？')">
						<img height="16" width="16" border="0" src="img/icon_trash.gif" alt="删除">
					</a>
					<%} %>
					</s:if>
					<s:else>
						<a href="category_show.do?type=upd&model.id=<%=mo.getId() %>">
							<img height="16" width="16" border="0" src="img/icon_view.gif" alt="查看">
						</a> 
					</s:else>
               </td>
               </tr>
                <%
				    for(Category mo1:list)
		  			{
		  				if((mo.getId()+"").equals(mo1.getParentId()))
	  					{
		  					%>
		  					<tr align="center" class="1" id="1_<%=mo1.getId() %>">
		  						<td align="left" class="first-cell" style="background-color: rgb(255, 255, 255); ">
		  						<img src="img/menu_minus.gif" id="icon_1_<%=mo1.getId() %>" width="9" height="9" border="0" style="margin-left:1em" onclick="rowClicked(this)">
		  						<span><%=mo1.getCategoryName()%></span>
		  						</td>
		  						<td width="24%" align="center" style="background-color: rgb(255, 255, 255); ">
		  							<s:if test="isUpdate.equals('true')">
								    			<a href="category_show.do?type=upd&model.id=<%=mo1.getId() %>">
								    			<img height="16" width="16" border="0" src="img/icon_edit.gif" alt="编辑"></a>
								    			&nbsp;
								    			<a href="category_save.do?type=del&model.id=<%=mo1.getId() %>" onclick="return window.confirm('警告！！确定要删除吗？')">
													<img height="16" width="16" border="0" src="img/icon_trash.gif" alt="删除">
												</a>
											 </s:if>
											 <s:else><a href="category_show.do?type=upd&model.id=<%=mo1.getId() %>">
													<img height="16" width="16" border="0" src="img/icon_view.gif" alt="查看">
												</a> 
											 </s:else>
		  						</td>
		  					</tr>
		  					<%
		  				} 
		  			}%>
	  			<%
  			}
  		}
  	}
%>
  </tbody>
  </table>
  </div>
   <script language="JavaScript">
<!--



var imgPlus = new Image();
imgPlus.src = "img/menu_plus.gif";

/**
 * 折叠分类列表
 */
function rowClicked(obj)
{
  // 当前图像
  img = obj;
  // 取得上二级tr>td>img对象
  obj = obj.parentNode.parentNode;
  // 整个分类列表表格
  var tbl = document.getElementById("list-table");
  // 当前分类级别
  var lvl = parseInt(obj.className);
  // 是否找到元素
  var fnd = false;
  var sub_display = img.src.indexOf('menu_minus.gif') > 0 ? 'none' : (Browser.isIE) ? 'block' : 'table-row' ;
  // 遍历所有的分类
  for (i = 0; i < tbl.rows.length; i++)
  {
      var row = tbl.rows[i];
      if (row == obj)
      {
          // 找到当前行
          fnd = true;
          //document.getElementById('result').innerHTML += 'Find row at ' + i +"<br/>";
      }
      else
      {
          if (fnd == true)
          {
              var cur = parseInt(row.className);
              var icon = 'icon_' + row.id;
              if (cur > lvl)
              {
                  row.style.display = sub_display;
                  if (sub_display != 'none')
                  {
                      var iconimg = document.getElementById(icon);
                      iconimg.src = iconimg.src.replace('plus.gif', 'minus.gif');
                  }
              }
              else
              {
                  fnd = false;
                  break;
              }
          }
      }
  }

  for (i = 0; i < obj.cells[0].childNodes.length; i++)
  {
      var imgObj = obj.cells[0].childNodes[i];
      if (imgObj.tagName == "IMG" && imgObj.src != 'img/menu_arrow.gif')
      {
          imgObj.src = (imgObj.src == imgPlus.src) ? 'img/menu_minus.gif' : imgPlus.src;
      }
  }
}
//-->
    </script>
    <!--Bottom开始-->
    
<div id="footer">
<br />
<script language="JavaScript">

if (document.getElementById("listDiv"))
{
  document.getElementById("listDiv").onmouseover = function(e)
  {
    obj = Utils.srcElement(e);

    if (obj)
    {
      if (obj.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode;
      else if (obj.parentNode.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode.parentNode;
      else return;

      for (i = 0; i < row.cells.length; i++)
      {
        if (row.cells[i].tagName != "TH") row.cells[i].style.backgroundColor = '#eeeded';
      }
    }

  }

  document.getElementById("listDiv").onmouseout = function(e)
  {
    obj = Utils.srcElement(e);

    if (obj)
    {
      if (obj.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode;
      else if (obj.parentNode.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode.parentNode;
      else return;

      for (i = 0; i < row.cells.length; i++)
      {
          if (row.cells[i].tagName != "TH") row.cells[i].style.backgroundColor = '#FFF';
      }
    }
  }

}

    </script>
<s:property value="bottom"/></div>
    <!--Bottom结束-->
</body>
</html>